﻿function fix(){      window.event.cancelBubble = true;      }


function hideSecurePad() 
{
    if (document.layers) 
    {
    document.layers['SecurePad'].visibility = "hide"
    }
    else if (document.all&&document.all['SecurePad']&&document.all['SecurePad'].style) 
    {
    document.all['SecurePad'].style.visibility = "hidden"
    }
    else if (document.getElementById&&document.getElementById('SecurePad')&&document.getElementById('SecurePad').style) 
    {
        document.getElementById('SecurePad').style.visibility = "hidden"
    }
    loseFocus = false;
}
 
 var loseFocus = false;
 var currentField;
 
function showSecurePad(obj) 
{
//1、保存对象
currentField = obj;
//2、计算SecurePad坐标

var t=obj.offsetTop - obj.parentElement.scrollTop;
var l=obj.offsetLeft - obj.parentElement.scrollLeft;


while(obj.offsetParent!=null && obj.offsetParent.parentElement!=null) {
obj=obj.offsetParent;
t+=obj.offsetTop - obj.parentElement.scrollTop;
l+=obj.offsetLeft - obj.parentElement.scrollLeft;
}
if(document.all['SecurePad']&&document.all['SecurePad'].style)
{
document.all['SecurePad'].style.top = t + 20;
if (l<120){
    document.all['SecurePad'].style.left = l + 50;
  }else{
     document.all['SecurePad'].style.left = l - 120;
}
//3、显示SecurePad
if (document.layers) {
document.layers['SecurePad'].visibility = "show"
}
else if (document.all) {
document.all['SecurePad'].style.visibility = "visible"
}
else if (document.getElementById) {
document.getElementById('SecurePad').style.visibility = "visible"
}
if(loseFocus)
    loseFocus=false;
}
}


function clickPad(num) 
{
if (num == "B") {
if(currentField.value.length > 0){

currentField.value = currentField.value.substring(1, currentField.value.length );

}
}
else if (num == "C") {
currentField.value = "";
}
else {
if(currentField.value.length <= (currentField.maxLength)-1)
switch(num)
{
    case 0:
      currentField.value = "7"+currentField.value; 
      break; 
    case 1:
      currentField.value = "4"+currentField.value; 
      break; 
    case 2:
      currentField.value = "3"+currentField.value; 
      break; 
    case 3:
      currentField.value = "6"+currentField.value; 
      break; 
    case 4:
      currentField.value = "9"+currentField.value; 
      break; 
    case 5:
      currentField.value = "1"+currentField.value; 
      break; 
    case 6:
      currentField.value = "0"+currentField.value; 
      break; 
    case 7:
      currentField.value = "2"+currentField.value; 
      break; 
    case 8:
      currentField.value = "5"+currentField.value; 
      break; 
    case 9:
      currentField.value = "8"+currentField.value; 
      break; 
}

}
loseFocus = false;
}
function closeSecurePad(){
 
if(loseFocus)
    hideSecurePad();
else
    loseFocus= true;
}
document.onclick = closeSecurePad;

 
